<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="container">
        <div class="btns">
            <button>1</button>
            <button>2</button>
            <button>3</button>
        </div>
        <div class="cons">
            <div class="dd">内容1</div>
            <div class="dd">内容2</div>
            <div class="dd">内容3</div>
        </div>
    </div>
    <script>
        function Table(btns, cons) {
            this.btns = document.querySelectorAll(btns)
            this.cons = document.querySelectorAll(cons)
            this.index = 0
            this.bindEvent()

        }
        Table.prototype.bindEvent = function () {
            var self = this
            this.change()
            for (var i = 0; i < self.btns.length; i++) {
                self.btns[i].index=i
                self.btns[i].onclick = function () {
                    self.index=this.index
                    console.log(777);
                    
                    self.change()

                }
            }
        }
        Table.prototype.change=function(){
            var self = this
            for(var i=0;i<self.cons.length;i++){
                
                self.cons[i].style.display='none'
                self.cons[self.index].style.display='block'
            }
        }
        var res = new Table('button', '.dd')
    </script>
</body>

</html>